package com.kly.enums;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


/**
 * 支付通道
 * @author linqu
 */
public enum PayGatewayEnum {

    /**
     * GOOGLE PAY 一次性商品支付
     */
    GOOGLE_PAY("1", "GOOGLE PAY"),
    /**
     * GOOGLE PAY 订阅类型商品支付
     */
    GOOGLE_PAY_SUBSCRIPTIONS("2", "GOOGLE PAY SUBSCRIPTIONS"),
    /**
     * PAYPAL 支付
     */
    PAY_PAL("3", "PAY PAL"),
    /**
     * 通用方法
     */
    GOOGLE_PAY_EXT("4", "GOOGLE PAY"),

    ;


    private String code;
    private String name;

    PayGatewayEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public PayGatewayEnum setCode(String code) {
        this.code = code;
        return this;
    }

    public String getName() {
        return name;
    }

    public PayGatewayEnum setName(String name) {
        this.name = name;
        return this;
    }

    public static PayGatewayEnum getEnumByCode(String code) {

        if (Objects.isNull(code)) {
            return null;
        }

        PayGatewayEnum payTypeEnum = null;

        for (PayGatewayEnum p : PayGatewayEnum.values()) {
            if (p.getCode().equals(code)) {
                payTypeEnum = p;
            }
        }
        return payTypeEnum;
    }


    public static List<PayGatewayEnum> getPaymentChannelEnumList() {
        List<PayGatewayEnum> payGatewayEnumList = new ArrayList<>();

        for (PayGatewayEnum paymentChannelEnum : PayGatewayEnum.values()) {
            payGatewayEnumList.add(paymentChannelEnum);
        }

        return payGatewayEnumList;
    }
}
